package mpo.serve.presistence;

import java.text.Format;
import java.util.Date;

import mpo.model.News;
import us.codecraft.webmagic.ResultItems;
import us.codecraft.webmagic.Task;
import us.codecraft.webmagic.pipeline.Pipeline;

public class Presistence implements Pipeline {

	public void process(ResultItems resultItems, Task task) {
		try {
			if (null != resultItems.get("url")) {
				News news = new News();
				news.set("url", String.valueOf(resultItems.get("url")));
				news.set("title", String.valueOf(resultItems.get("title")));
				news.set("content", String.valueOf(resultItems.get("content")));
				news.set("description",
						String.valueOf(resultItems.get("description")));
				news.set("source", String.valueOf(resultItems.get("source")));
				news.set("keywords",
						String.valueOf(resultItems.get("keywords")));
				news.set("date", String.valueOf(resultItems.get("date")));
				news.set("media", String.valueOf(resultItems.get("media")));
				
				news.set("picktime", new Date());
				news.save();
			}
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}
}
